package unittests;

import java.util.Date;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import Controller.Client;
import Controller.ParkingLotWorkerController;
import Entity.FullSubscription;
import Entity.OneTimeCostumerOrder;

public class CheckoutTest extends TestCase
{
	private OneTimeCostumerOrder o;
	private FullSubscription f;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception 
	{
		Client.testing();
	}

	@After
	public void tearDown() throws Exception {
	}

	public CheckoutTest(String s) 
	{
		super(s);
	}
	
	@Test
	public void test1() throws Exception //check successful case of occasional customer
	{
		float expected=(float) 10.0;
		Date d=new Date();
		d.setTime(d.getTime()-1000*60*60*2);
		o=new OneTimeCostumerOrder("307958512",new Date(),d,null,"a@a.com","1234567",false,0);
		o.saveToDB();
		Client.getParkingLots_sorted()[0].insertCar(o.getCar_number(),o.getLeaving_hour());
		ParkingLotWorkerController.carCheckout("1234567");
		float result=o.getPayment();
		Assert.assertEquals(expected, result);
	}
	
	@Test
	public void test2() // check checkout of customer that not exists
	{
		String expected="The car were not found";
		
		try {
			ParkingLotWorkerController.carCheckout("9876543");
		}
		catch(Exception e)
		{
			Assert.assertEquals(expected,e.getMessage());
		}
	}
	
	@Test
	public void test3() throws Exception //check successful case of full subscriber
	{
		f=new FullSubscription("5","311156731","1357913",new Date(2014,0,4,10,0),new Date(2014,5,4,10,0));
		f.save();
		Client.getParkingLots_sorted()[0].insertCar(f.getCar_number(),new Date());
		Assert.assertTrue(ParkingLotWorkerController.carCheckout("1357913"));
	}
	
	/*public void test4() throws Exception //check if the subscriber get penalty when his subscription ends
	{
		int expected=1;
		f=new FullSubscription("5","311156731","1357913",new Date(2014,0,3,10,0),new Date(2014,1,3,10,0));
		f.save();
		
		Client.getParkingLots_sorted()[0].insertCar(f.getCar_number(),new Date());
		ParkingLotWorkerController.carCheckout("1357913");
		Assert.assertEquals(expected,f.getPenalty());
	}*/
}

/*$CPS$ This comment was generated by CodePro. Do not edit it.
 * patternId = com.instantiations.assist.eclipse.pattern.testCasePattern
 * strategyId = com.instantiations.assist.eclipse.pattern.testCasePattern.junitTestCase
 * additionalTestNames = 
 * assertTrue = false
 * callTestMethod = true
 * createMain = false
 * createSetUp = true
 * createTearDown = true
 * createTestFixture = false
 * createTestStubs = false
 * methods = 
 * package = unittests
 * package.sourceFolder = VCP_G14/src
 * superclassType = junit.framework.TestCase
 * testCase = TestCaseTest
 * testClassType = junit.framework.TestCase
 */